package com.service.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.service.gmall.common.result.Result;
import com.service.gmall.model.product.SkuInfo;
import com.service.gmall.product.service.SkuInfoService;
import com.service.gmall.product.service.SpuSaleAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author alpha
 * @className: SkuController
 * @date 2022/8/30 12:39
 * @Description
 */
@RestController
@RequestMapping("/admin/product/")
public class SkuController {
    @Autowired
    SkuInfoService skuInfoService;

//    /admin/product/list/1/10

    /**
     * 查询分页信息
     * @param page pagenum
     * @param limit pagesize
     * @return
     */
    @GetMapping("/list/{page}/{limit}")
    public Result getSkuList(@PathVariable("page")Long page,
                             @PathVariable("limit")Long limit){
        Page<SkuInfo> infoPage = new Page<>(page,limit);
        Page<SkuInfo> skuInfoPage = skuInfoService.page(infoPage);
        return Result.ok(skuInfoPage);
    }

//  admin/product/saveSkuInfo

    /**
     * sku保存
     * @param skuInfo
     * @return
     */
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        skuInfoService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

//    admin/product/onSale/{skuId}

    /**
     * 上架
     * @param skuId
     * @return
     */
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId")Long skuId){
        skuInfoService.onsale(skuId);
        return Result.ok();

    }

    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId")Long skuId){
        skuInfoService.cancelSale(skuId);
        return Result.ok();

    }

    /**
     * 修改sku信息
     * @param skuInfo
     */
    public void updateSkuInfo(SkuInfo skuInfo){
//        skuInfoService.updateSkuInfo();
//        cacheOpsService.delay2Delete(skuInfo.getId());
    }
}
